/********************************************************************/
/*  Copyright (C) School of Software Engineering of USTC, 2012                               
/*                                                                                                                       
/*  FILE NAME: event.c                                                                                          
/*  PRINCIPAL AUTHOR: SA12226114(Xin Zhu), SA12226139(Dan Shu)                    
/*  SUBSYSTEM NAME:                                                                                     
/*  MODULE NAME: event                                                                                    
/*  LANGUAGE: C                                                                                                 
/*  TARGET ENVIRONMENT: Linux                                                                          
/*  DATE OF FIRST RELEASE: 2012-12-20                                                             
/*  DESCRIPTION: Impement of Abstract Interface for Tokyo Cabinet DB API              
/********************************************************************/



#include "event.h"



/*****************************************************************
Function Name: initialize an event
Description: 
Parameter:  

Author: SA12226114(Xin Zhu), SA12226139(Dan Shu)
Date: 2012-12-20
******************************************************************/
int init_event(sem_t *pevent, int value)
{
    if(sem_init(pevent, 0, value) != EVENT_TRUE)
    {
        printf("sem_init failed\n");
        
        return EVENT_FALSE;
    }
    
    return EVENT_TRUE;
}


/*****************************************************************
Function Name: 
Description: 
Parameter:  

Author: SA12226114(Xin Zhu), SA12226139(Dan Shu)
Date: 2012-12-20
******************************************************************/
int destroy_event(sem_t *pevent)
{
    sem_destroy(pevent);
    
    return EVENT_TRUE;
}


/*****************************************************************
Function Name: 
Description: 
Parameter:  

Author: SA12226114(Xin Zhu), SA12226139(Dan Shu)
Date: 2012-12-20
******************************************************************/
int post_event(sem_t *pevent)
{
    return sem_post(pevent);
}


/*****************************************************************
Function Name: 
Description: 
Parameter:  

Author: SA12226114(Xin Zhu), SA12226139(Dan Shu)
Date: 2012-12-20
******************************************************************/
int wait_event(sem_t *pevent)
{
    return sem_wait(pevent);
}




